
<div class="templatemo-content-wrapper">
	<div class="templatemo-content">
		<ol class="breadcrumb">
			<li><a href="<?=site_url()?>/supply/index">进货单管理</a></li>
			<li class="active">编辑进货单</li>
		</ol>
		<div class="row margin-bottom-30">
			<div class="col-md-12">
				<ul class="nav nav-pills">
					<li class="active"><a href="<?=site_url()?>/supply/index">返回进货单列表</a></li>
				</ul>
			</div>
		</div>
		<div class="row">
			<div class="col-md-12">
				<div class="table-responsive">
					<h4 class="margin-bottom-15">添加进货单</h4>
					<form role="form" id="templatemo-preferences-form"
						onsubmit="return false;">
						<div class="row">
							<div class="col-md-6 margin-bottom-15">
								<label for="firstName" class="control-label">商品名称</label> <input
									type="text" class="form-control" id="name" value="<?php echo $supply['name'].'-'.$supply['productid']; ?>">
							</div>
							<div class="col-md-6 margin-bottom-15">
								<label for="lastName" class="control-label">进货价</label> <input
									type="text" class="form-control" id="price" value="<?php echo $supply['price']; ?>">
							</div>
							<div class="col-md-6 margin-bottom-15">
								<label for="firstName" class="control-label">数量</label> <input
									type="text" class="form-control" id="amount" value="<?php echo $supply['amount']; ?>">
							</div>
							<div class="col-md-6 margin-bottom-15">
								<label for="lastName" class="control-label">单位</label> <input
									type="text" class="form-control" id="unit" value="<?php echo $supply['unit']; ?>">
							</div>
							<div class="col-md-6 margin-bottom-15">
								<label for="firstName" class="control-label">总价(元)</label> <input
									type="text" class="form-control" id="total" value="<?php echo $supply['total']; ?>">
							</div>
							<div class="col-md-6 margin-bottom-15">
								<label for="firstName" class="control-label">进货时间</label> <input
									type="text" class="form-control" id="buytime" value="<?php echo date("Y-m-d",strtotime($supply['supply_time'])); ?>">
							</div>
							<div class="col-md-6 margin-bottom-15">
								<label for="lastName" class="control-label">备注</label> <input
									type="text" class="form-control" id="note" value="<?php echo $supply['note']; ?>">
							</div>
						</div>
						<div class="row templatemo-form-buttons">
							<div class="col-md-12">
								<input type="hidden"  id="supplyid" value="<?php echo $supply['id']; ?>">
								<button type="submit" class="btn btn-primary" id="submit_btn">修改</button>
							</div>
						</div>
					</form>
				</div>
			</div>
		</div>
	</div>
</div>
<script>
	$(document).ready(function() {
		$("#submit_btn").click(function() {
			var id = $("#supplyid").val();
			var name = $("#name").val();
			var price = $("#price").val();
			var amount = $("#amount").val();
			var unit = $("#unit").val();
			var total = $("#total").val();
			var buytime = $("#buytime").val();
			var note = $("#note").val();
			$.ajax({
				url : '<?php echo site_url('supply/save')?>',
				type : "post",
				async : true,
				data : {
					'id' : id,
					'name' : name,
					'price' : price,
					'amount' : amount,
					'unit' : unit,
					'total' : total,
					'buytime' : buytime,
					'note' : note
				},
				dataType : "json",
				timeout : "1000",
				error : function() {
					alert("服务加载出错");
				},
				success : function(data) {
					if(data.code)
					{
						alert(data.msg);
					}else{
						alert(data.msg);
					}
				}
			});
		});
		$('#buytime').datepicker({
			dateFormat: 'yy-mm-dd',
			monthNames: ['一月','二月','三月','四月','五月','六月','七月','八月','九月','十月','十一月','十二月'],
			dayNamesMin: ['日','一','二','三','四','五','六']
		});
	}); 
</script>